#
# 
# Author: Guochun
###############################################################################

#' @title  Copy all source R code to the R fold under the package root fold
#' @name CopyToRFold
#' @param from the fold names that contain the newest version of R codes
#' @param to the destination fold. "./R" is the default fold that specified by R CMD functions
#' @note just set the work direction into the package root fold, then run this funciton
#'  Using this function, we can put different codes under different folds.
#'  before building or install the package, just run it to copy all of the code
#'  to the R fold, thus R CMD INSTALL/BUILD can see them.
#' 
#' 


copyToRFold=function(from="./srr",to="./R"){
	#get all files under the R fold
	allfiles=list.files(from,include.dirs=FALSE,recursive=TRUE)
	#select files only existed in subdir of R fold
	is_subdir_files=unlist(lapply(strsplit(allfiles,"/"),length))==2
	#names of files that need to be copy
	copyfilenames=paste(from,"/",allfiles[is_subdir_files],sep="")
	#copy all subdir files under R fold
	file.copy(copyfilenames,to,overwrite=TRUE)
}
